package com.stylefeng.guns.modular.pay.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.pay.model.BankLimit;
import com.stylefeng.guns.modular.pay.service.IBankLimitService;

/**
 * 银行限额
 *
 * @author 
 * @Date 2018-09-26 11:18:50
 */
@Controller
@RequestMapping("/bankLimit")
public class BankLimitController extends BaseController {

    private String PREFIX = "/pay/bankLimit/";

    @Autowired
    private IBankLimitService bankLimitService;

    /**
     * 跳转到银行限额首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "bankLimit.html";
    }

    /**
     * 跳转到添加银行限额
     */
    @RequestMapping("/bankLimit_add")
    public String bankLimitAdd() {
        return PREFIX + "bankLimit_add.html";
    }

    /**
     * 跳转到修改银行限额
     */
    @RequestMapping("/bankLimit_update/{bankLimitId}")
    public String bankLimitUpdate(@PathVariable Integer bankLimitId, Model model) {
        BankLimit bankLimit = bankLimitService.selectById(bankLimitId);
        model.addAttribute("item",bankLimit);
        LogObjectHolder.me().set(bankLimit);
        return PREFIX + "bankLimit_edit.html";
    }

    /**
     * 获取银行限额列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return bankLimitService.selectList(null);
    }

    /**
     * 新增银行限额
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(BankLimit bankLimit) {
        bankLimitService.insert(bankLimit);
        return SUCCESS_TIP;
    }

    /**
     * 删除银行限额
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer bankLimitId) {
        bankLimitService.deleteById(bankLimitId);
        return SUCCESS_TIP;
    }

    /**
     * 修改银行限额
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(BankLimit bankLimit) {
        bankLimitService.updateById(bankLimit);
        return SUCCESS_TIP;
    }

    /**
     * 银行限额详情
     */
    @RequestMapping(value = "/detail/{bankLimitId}")
    @ResponseBody
    public Object detail(@PathVariable("bankLimitId") Integer bankLimitId) {
        return bankLimitService.selectById(bankLimitId);
    }
}
